#include "gl/glut.h"
#include "Lol.h"
#include "SOIL.h"
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
float yAxisRotate = 0;

using namespace Lol;
LolSknHeader* sknHeader = 0;
struct texinfo
{
	unsigned char* data;
	int w;
	int h;
	int channel;
	GLuint texid;
};

texinfo g_tex;
void init()
{
	glClearColor(0.0,0.1,0.5,1.0);
	sknHeader = loadSkn("H:\\LOLView\\Ashe.skn");
	g_tex.data = SOIL_load_image("H:\\LOLView\\ashe_base_2011_TX_CM.dds",&g_tex.w,&g_tex.h,&g_tex.channel,SOIL_LOAD_AUTO);
	
	// SOIL_load_OGL_texture()
	glGenTextures(1,&(g_tex.texid));
	glBindTexture(GL_TEXTURE_2D,g_tex.texid);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);	

	glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,g_tex.w,g_tex.h,0,GL_RGB,GL_UNSIGNED_BYTE,g_tex.data);

	free(g_tex.data);



	// --------------
	LolAnmHeader*anm = loadAnm("K:\\LOLView\\Ashe\\Animations\\ashe_attack1.anm");

	
}

void reshape(int w,int h)
{
	glViewport(0,0,w,h);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45,1.333,10,10000);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void display()
{
	glShadeModel(GL_SMOOTH);
	//glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH);
	glEnable(GL_DEPTH_TEST);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0,330,300,0,0,0,0,1,0);
	glPushMatrix();
	yAxisRotate += 0.5;
	glRotatef(yAxisRotate,0,yAxisRotate,0);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_COLOR);
	glColor3f(1.0,0.5,1.0);

	drawSkn(sknHeader,g_tex.texid);

	glPopMatrix();
	glutSwapBuffers();
	Sleep(10);
	glutPostRedisplay();
}


int main(int argc, char *argv[])
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
	glutInitWindowPosition(100,100);
	glutInitWindowSize(800,600);
	glutCreateWindow("lol model view");
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);

	init ();

	glutMainLoop();
	freeSkn(sknHeader);
}